import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
        System.out.println("=== 简易计算器（输入q退出）===");
        while(true){
            try {
                System.out.println("请输入第一个数字");
                String num1Str=sc.next();
                if("q".equals(num1Str)) break;
                double num1=Double.parseDouble(num1Str);

                System.out.println("请输入符号+、-、*、/");
                String operator = sc.next();

                System.out.println("请输入第二个数字");
                String num2Str=sc.next();
                if("q".equals(num2Str)) break;
                double num2 = Double.parseDouble(num2Str);

                double result=0;
                boolean validOperator=true;
                switch (operator){
                    case "+":result=num1+num2;
                    break;
                    case "-":result=num1-num2;
                    break;
                    case "*":result=num1*num2;
                    break;
                    case "/":result=num1/num2;
                    if(num2==0){
                        System.out.println("❌ 错误：除数不能为0！");
                        validOperator=false;
                        break;
                    }
                    result=num1/num2;
                    break;
                    default:
                        System.out.println("❌ 错误：运算符只能是 +、-、*、/！");
                        validOperator=false;
                }

                // 5. 输出结果
                if (validOperator) {
                    System.out.println("✅ 结果：" + num1 + " " + operator + " " + num2 + " = " + result);
                }
                System.out.println("------------------------");
            }catch (NumberFormatException e) {
                // 处理输入非数字的情况
                System.out.println("❌ 错误：请输入有效的数字！");
                System.out.println("------------------------");
            }
        }
    }
}
